package source.model;

import java.util.Hashtable;
import java.util.Vector;

import source.model.type.GameObjectType;

public class UnitData implements GameData {

	private Hashtable<String, Unit> dataList;
	private final GameObjectType dataType = GameObjectType.UNIT;
	
	public UnitData() {
		dataList = new Hashtable<String, Unit>();
	}
	
	public boolean dataMatch( GameObjectType got ) {
		return got.equals( dataType );
	}
	
	public boolean addObject( GameObject go ) {
		if ( dataMatch( go.objectType() ) && !dataList.containsKey( go.objectID().getID() ) )
		{
			Unit d = dataList.put( go.objectID().getID(), (Unit) go );
			if ( d != null) return false;
			return true;
		}
		else
			return false;
	}
	
	public Unit getObject( ObjectID id ) {
		return dataList.get( id.getID() );
	}
	
	public boolean removeObject( GameObject go ) {
		return !(dataList.remove( go.objectID().getID() ) == null);
	}
	
	public Vector<GameObject> getAllObjects (GameObjectType got)
	{
		if(this.dataType == got)
		{
		Vector<GameObject> v = new Vector<GameObject>();
		for( Unit u : dataList.values() )
		{
		v.add(u);
		}
		return v;
		}
		else
			return null;	
	}
}
